#ifndef GRAPHICSSQUARE_H
#define GRAPHICSSQUARE_H

#include <AStarSolver.h>
#include <QFlags>
#include <QGraphicsItem>

class GraphicsSquare : public QGraphicsItem
{
public:
    enum
    {
        Type = UserType + 1
    };
    int type() const { return Type; }

    GraphicsSquare();

    int sqType; // 种类
    int x;
    int y;
    float cost;

    enum sqState
    {
        CURRENT = 1,
        SOURCE = 2,
        DESTINATION = 4,
        FRONTIER = 8,
        BEST = 16,
        TRACE = 32,
        CALCULATED = 64,
        PATH=128
    }; // 当前状态
    Q_DECLARE_FLAGS(sqStates, sqState)
    sqStates states;
    void setState(sqState state,bool on=true) { states.setFlag(state,on); }

    void setWidth(int w) { m_rect = QRectF(0, 0, w, w); }

    static void setSquareWidth(qreal width) { SQUARE_WIDTH = width; }
    static qreal SQUARE_WIDTH;

public:
    QRectF boundingRect() const;
    void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
               QWidget* widget);

    Location loc(){return Location{x,y};}
private:
    QRectF m_rect;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(GraphicsSquare::sqStates)

#endif // GRAPHICSSQUARE_H
